/****************************
 *Layer1.2    作者：kevin
 *
***************************/
;+(function(win,$){
	"use strict";
	/***********************
	 * $.layer.photos(json,option) 相册
	 * json=[{url:'',title:'',intro:''}]
	 option.view	视图类型,preview:预览，list:列表
	 option.curren	当前位置序号
	***********************/
	$.layer.photos=function(json,option){
		option=$.extend({head:{title:'相册',btn:[{text:'返回',icon:''},{text:'视图',icon:'fr viewbtn',isclose:0}]},view:'preview',className:'',anim:'zoom',current:0,type:'photos'},option||{});
		option.className+=' kui-photos';
		var imglist=$.map(json,function(itm,i){
			return '<div class="img-item"><img data-src="'+itm.src+'" /><span class="img-intro">'+itm.intro+'</span></div>';
		}).join('');
		option.content='<div class="kui-photos-inner" style="">'+imglist+'</div>';
		option.foot='底部控制';
		
		//显示相册
		var photos=$.layer(option);
		photos.on('show',function(){
			//页面初始化后，加载图片
			photos.find('[data-src]').each(function(){
				$(this).attr({src:$(this).attr('data-src')}).removeAttr('data-src');
			})
		})
		
		//默认视图
		var view=option.view;
		setView(photos);
		//视图切换
		photos.find('.viewbtn').on(tap,function(){
			view=view=='preview'?'list':'preview';
			setView(photos);
		});
		
		function setView(ps){
			//设置显示样式
			ps.attr({view:view});
			if(view=='preview'){
				var len=ps.find('.img-item').size();
				//设置宽度
				ps.find('.kui-photos-inner').attr({style:'width:'+len+'00%;-webkit-column-count:'+len});
				ps.find('.img-item').on(tap,function(){
					
				})
			}else{
				ps.find('.kui-photos-inner').removeAttr('style');
				ps.find('.img-item').on(tap,function(){
					view='preview';
					setView(ps,view);
					ps.find('.kui-layer-content').scrollLeft($(this).index()*$(this).width())
				})
			}
		}
		return photos;
	}
}(window,Zepto))